<!doctype html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>用户登录&注册页|私教预约系统</title>
	<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico" />
	<link rel="stylesheet" type="text/css" href="../css/normalize.css" />
	<link rel="stylesheet" type="text/css" href="../css/default.css">
	<link rel="stylesheet" type="text/css" href="../css/styles.css">
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="../css/materialdesignicons.min.css" />
	<link rel="stylesheet" type="text/css" href="../css/style.min.css" />
	<link href="../css/coming-soon.min.css" rel="stylesheet">

</head>
<body>

<div class="overlay"></div>
<video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
	<source src="../mp4/exercise.mp4" type="video/mp4">
</video>

<div class="masthead">
	<div class="container h-100">
		<div class="row h-100">
			<div class="col-12 my-auto">
				<div class="masthead-content text-white py-5 py-md-0">
					<p></p>
					<div class="htmleaf-container">
						<div class="login-wrap">
							<div class="login-html">
								<input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">登录</label>
								<input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">注册</label>
								<div class="login-form">
									<div class="sign-in-htm">
										<div class="group">
											<label for="user_in" class="label">用户名</label>
											<input id="user_in" type="text" class="input" >
										</div>
										<div class="group">
											<label for="pass_in" class="label">密码</label>
											<input id="pass_in" type="password" class="input" data-type="password">
										</div>
										<div class="group">
											<input id="check" type="checkbox" class="check" checked>
											<label for="check"><span class="icon"></span> 保存密码</label>
										</div>
										<div class="group">
											<input id="signin" type="submit" class="button" value="登录">
										</div>
										<div class="hr"></div>
										<div class="foot-lnk">
											<a href="userPwdReset.html" class="forget-pwd">忘记密码？</a>
										</div>
									</div>
									<div class="sign-up-htm">
										<div class="group">
											<label for="user_up" class="label">用户名</label>
											<input id="user_up" type="text" class="input">
										</div>
										<div class="group">
											<label for="pass_up" class="label">密码</label>
											<input id="pass_up" minlength="6" required type="password" class="input" data-type="password">
										</div>
										<div class="group">
											<label for="pass_a" class="label">重复密码</label>
											<input id="pass_a" type="password" class="input" data-type="password">
										</div>
										<!--<div class="group">
											<label for="pass_e" class="label">Email Address</label>
											<input id="pass_e" type="text" class="input">
										</div>-->
										<div class="group">
											<input id="signup" type="submit" class="button" value="注册">
										</div>
										<div class="hr"></div>
										<div class="foot-lnk">
											<label for="tab-1">Already Member?</label>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


</body>
<script src="../js/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery("#signin").click(function () {
			let name = jQuery("#user_in").val();
			let pwd=jQuery("#pass_in").val();

			jQuery.post("/user_signIn",{"userName":name,"userPassword":pwd},function(rst) {


				if(rst === "登录成功"){

					jQuery.post("/getUserInfoByName", {"userName" : name}, function (rst) {
						var id = rst.userId;
						$.cookie('userid', id);
						$.cookie('username', name);
						window.location.replace("userMainPage.html");
					})
				}else{
					alert(rst);
				}
			});
		})
	});



	jQuery(document).ready(function () {
		jQuery("#signup").click(function () {
			let js = signup();

			let judge_one = check(js);

			let judge_three = false;
			if(js !== "重复密码错误！"){
				judge_three = true;
			}
			jQuery.post("/sign_repeateNameCheck", js, function (rst) {
				if ("OK" !== rst) {
					alert(rst);
				}
			})
			if (judge_three && judge_one) {
				jQuery.post("/user_signUp", js, function (rst) {
					if (rst === "注册成功"){
						alert("注册成功");
						window.location.reload();
					} else
						alert("注册失败");
				})
			}
		})
	})

	function signup() {
		let name = jQuery("#user_up").val();
		let pwd = jQuery("#pass_up").val();
		let pwd_a = jQuery("#pass_a").val();

		let now = new Date();
		let year=now.getFullYear();
		let month=now.getMonth()+1;
		let date=now.getDate();
		if (month<10)
			month="0"+month;
		if (date<10)
			date="0"+date;
		var submitDate=year+"-"+month+"-"+date;


		// let email = jQuery("#pass_e").val();
		if (pwd === pwd_a) {
			return {"userName": name, "userPassword": pwd, "userSignDate": submitDate}
		} else {
			alert("重复密码错误！")
		}
	}

	function check(js) {
		let strname = js.userName.replace(/(^\s*)|(\s*$)/g,'');
		//let stremail = js.userPassword.replace(/(^\s*)|(\s*$)/g,'');
		let strpwd = js.userPassword.replace(/(^\s*)|(\s*$)/g,'');
		if(strname==='' || strname===undefined){
			alert("用户名不可为空")
		}
		/*else if(stremail ==='' || stremail===undefined){
			alert("邮箱不可为空")
		}*/
		else if(strpwd ==='' || strpwd===undefined){
			alert("密码不可为空")
		}else {
			return true
		}
	}

</script>
</html>